package com.zuipin.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zuipin.entity.BaseDictionaryData;
import com.zuipin.entity.product.ProductExtInfo;
import com.zuipin.mapper.BaseDictionaryDataMapper;
import com.zuipin.service.IBaseDictionaryDataService;
import com.zuipin.service.IProductExtInfoService;
import com.zuipin.util.Pagination;
import com.zuipin.vo.BaseDictionaryDataVo;

import net.sf.json.JSONObject;

/**
 * 字典数据值服务实现
 * 
 * @ClassName: BaseDictionaryDataSer5viceImpl
 * @Description: TODO
 * @author robot
 * @date 2017年04月247日 16:56:13
 */
@Service
public class BaseDictionaryDataServiceImpl implements IBaseDictionaryDataService {

	@Resource
	private BaseDictionaryDataMapper baseDictionaryDataMapper;
	@Resource
	private IProductExtInfoService productExtInfoService;

	@Override
	public BaseDictionaryData findById(Long id) {
		return baseDictionaryDataMapper.findById(id);
	}

	@Override
	public void insert(BaseDictionaryData baseDictionaryData) {
		baseDictionaryDataMapper.insert(baseDictionaryData);
	}

	@Override
	public void update(BaseDictionaryData baseDictionaryData) {
		baseDictionaryDataMapper.update(baseDictionaryData);
	}

	@Override
	public void delete(Long id) {
		baseDictionaryDataMapper.delete(id);

	}

	@Override
	public List<BaseDictionaryDataVo> seachBaseDictionaryData(BaseDictionaryData baseDictionaryData, Pagination page) {
		return baseDictionaryDataMapper.seachBaseDictionaryData(baseDictionaryData);
	}

	@Override
	public List<BaseDictionaryData> seachTagInfo(BaseDictionaryData baseDictionaryData, Pagination page) {
		// TODO Auto-generated method stub
		return baseDictionaryDataMapper.seachTagInfo(baseDictionaryData, page);
	}

	@Override
	public BaseDictionaryData isExists(JSONObject params) {
		// TODO Auto-generated method stub
		return baseDictionaryDataMapper.isExists(params);
	}

	@Override
	public boolean modifyActive(JSONObject params) {
		// TODO Auto-generated method stub
		return baseDictionaryDataMapper.modifyActive(params);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public boolean insertSelective(BaseDictionaryData tagInfo, List<ProductExtInfo> proSkus) {
		// TODO Auto-generated method stub
		boolean flag = false;
		flag = baseDictionaryDataMapper.insertSelective(tagInfo);
		if (flag && proSkus.size() > 0) {
			for (ProductExtInfo productExtInfo : proSkus) {
				productExtInfo.setTagId(tagInfo.getId());
			}
			//productExtInfoService.updateTagInfoBatch(proSkus);
		}
		return flag;
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public boolean updateByPrimaryKeySelective(BaseDictionaryData tagInfo, List<ProductExtInfo> proSkus) {
		// TODO Auto-generated method stub
		boolean flag = false;
		flag =baseDictionaryDataMapper.updateByPrimaryKeySelective(tagInfo);
		if (flag && proSkus.size() > 0) {
			for (ProductExtInfo productExtInfo : proSkus) {
				productExtInfo.setTagId(tagInfo.getId());
			}
			//productExtInfoService.updateTagInfoBatch(proSkus);
		}
		return flag;
	}

	@Override
	public BaseDictionaryData findTagInfoById(BaseDictionaryData tagInfo) {
		// TODO Auto-generated method stub
		return  baseDictionaryDataMapper.findTagInfoById(tagInfo);
	}

}
